package com.suxii.frpclient.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.suxii.frpclient.R;

import java.util.ArrayList;
import java.util.List;

public class LogAdapter extends RecyclerView.Adapter<LogAdapter.LogViewHolder> {

    private Context context;
    private final List<String> list = new ArrayList<>();

    public LogAdapter(Context context) {
        this.context = context;
    }

    public void addData(String text){
        list.add(text);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public LogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_log, parent,false);
        return new LogViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull LogViewHolder holder, int position) {
        holder.logText.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class LogViewHolder extends RecyclerView.ViewHolder{

        private TextView logText;

        public LogViewHolder(@NonNull View itemView) {
            super(itemView);
            logText = itemView.findViewById(R.id.log_text);
        }
    }
}
